class Solution {
public:
    TreeNode* reConstructBinaryTree(vector<int> pre, vector<int> vin) 
    {
        int n = pre.size();
        int m = vin.size();
        if (n == 0 || m == 0)
            return NULL;
        TreeNode* root = new TreeNode(pre[0]);
        for (int i = 0; i < vin.size(); i++) 
        {
            if (pre[0] == vin[i]) 
            {
                vector<int> leftpre(pre.begin() + 1, pre.begin() + i + 1);
                vector<int> leftvin(vin.begin(), vin.begin() + i);
                root->left = reConstructBinaryTree(leftpre, leftvin);
                vector<int> rightpre(pre.begin() + i + 1, pre.end());
                vector<int> rightvin(vin.begin() + i + 1, vin.end());
                root->right = reConstructBinaryTree(rightpre, rightvin);
                break;
            }
        }
        return root;
    }
};
